package BeenChina.PM.Action; 
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.StringUtils;

import BeenChina.PM.Model.ModelBaseInfo;
import BeenChina.PM.Model.ModelCaseInfo;
import BeenChina.PM.Service.ServiceFactory;
import BeenChina.PM.Util.JqGridBaseAction;
import BeenChina.PM.Util.StringUtil;

public class BaseInfoQueryAction extends JqGridBaseAction<ModelBaseInfo> {	
		
	private static final long serialVersionUID = 1L;
	private List<ModelBaseInfo> baseInfoList =new ArrayList<ModelBaseInfo>(); 
	private List<ModelCaseInfo> caseList = new ArrayList<ModelCaseInfo>();
		
	private String[] cases,ranks;	
	private String dateFrom,dateTo,dateFiled;;

	public void setCases(String[] cases){
		this.cases = cases;
	}

	public void setRanks(String[] ranks){
		this.ranks = ranks;
	}

	public void setDateFrom(String dateFrom){
		this.dateFrom = dateFrom;
	}

	public void setDateTo(String dateTo){
		this.dateTo = dateTo;
	}

	public String getDateField(){ 	
		return this.dateFiled;	
	}

	public void setDateField(String dateField){ 	
		this.dateFiled  = dateField;	
	}
	
	 @Override
	 public String execute() {
		 dateFiled="receiptdate";
		 caseList = ServiceFactory.getInstance().getCommonInfoService().selectCaseNames();
		 return "load";
	 }
	 
	 @Override
	 protected List<ModelBaseInfo> listResults(int from, int length) throws Exception { 
		 try
		 {
			 String caseStr=StringUtils.join(cases,",");
			 String rankStr=StringUtils.join(ranks,",");
			 
			 if (StringUtil.isDate(dateFrom) &&   StringUtil.isDate(dateTo)  )
			 {	 
				 baseInfoList = ServiceFactory.getInstance().getBaseInfoService().selectBaseInfos(caseStr, rankStr, this.dateFrom, this.dateTo,this.dateFiled);
			 }			 
			 return baseInfoList;
		 }
		 catch(Exception exp)
		 {
			 throw exp;
		 }
	 }

	@Override
	public int getResultSize() {
		return this.baseInfoList.size();
	}

	public List<ModelCaseInfo> getCaseList() {
		return caseList;
	}
}
 
